﻿using System;
using EstimateTracker.DataAccess.Repositories;
using Moq;
using NUnit.Framework;

namespace EstimateTracker.Services.Tests
{
    [TestFixture]
    public class TimerServiceTest
    {
        [Test]
        public void ConvertMinutesToDecimal_WithTimeSpanThatContainsHoursAsMinutes_ReturnsMinutesOnlyAsFraction()
        {
            // Arrange
            
            double result = 10;
            
            // Act
            var service = new TimerService(Mock.Of<IHoursWorkedRepository>());

            result = service.UpdateTime(10, new TimeSpan(0,0, 0));
            Assert.That(result, Is.EqualTo(10.0));

            result = service.UpdateTime(10, new TimeSpan(0, 6, 0));
            Assert.That(result,Is.EqualTo(10.1));

            result = (service.UpdateTime(10, new TimeSpan(0, 6, 0)));
            Assert.That(result,Is.EqualTo(10.1));

            result = service.UpdateTime(10, new TimeSpan(0, 7, 0));
            Assert.That(result, Is.EqualTo(10.1));

            result = service.UpdateTime(10, new TimeSpan(0, 8, 0));
            Assert.That(result, Is.EqualTo(10.1));

            result = service.UpdateTime(10, new TimeSpan(0, 9, 0));
            Assert.That((decimal)result, Is.EqualTo(10.1));

            result = service.UpdateTime(10, new TimeSpan(0, 12, 0));
            Assert.That(result, Is.EqualTo(10.2));

            result = service.UpdateTime(10, new TimeSpan(0, 12, 0));
            Assert.That(result, Is.EqualTo(10.2));

            result = service.UpdateTime((10), new TimeSpan(0, 13, 0));
            Assert.That(result, Is.EqualTo(10.2));

            result = service.UpdateTime((10), new TimeSpan(0, 18, 0));
            Assert.That(result, Is.EqualTo(10.3));

            result = service.UpdateTime((10), new TimeSpan(0, 24, 0));
            Assert.That(result, Is.EqualTo(10.4));
        } 
    }
}